<?php

namespace app\logic\index;

class L_adPosition
{
    /**
     * 获取广告位
     * @params string 1 index
     * @params int 0 limit
     * @param string $paramObj
     */
    public function getList($paramObj=""){
        $dataObj=paramsObj();
        $dataObj->request=paramsObj();
        $dataObj->data=paramsObj();
        $dataObj->data->use_trans=false;
        $dataObj->result=array();

        $final_arr=logInit();
        if($final_arr["error_no"]==0){
            $mixed=parseToArr($paramObj,"mixed",0);
            $params=parseToArr($paramObj,"params",array());
            $messages=parseToArr($paramObj,"messages",array());
            $rules=array(
                'index' => 'require',
                "offset"=>"",
                "limit"=>"",
            );
            $dataDefault=array();
            $paramsObj=paramsObj();
            $paramsObj->params=$params;
            $paramsObj->mixed=$mixed;
            $paramsObj->rules=$rules;
            $paramsObj->messages=$messages;
            $paramsObj->dataDefault=$dataDefault;
            $checkResult = app("verifyParam")::validatorRequest($paramsObj);
            if($checkResult["error_no"]==0){
                $dataObj->request=$checkResult["result"];
            }else{
                $final_arr=logCallErrorMsg($final_arr,$checkResult);
            }
        }
        if($final_arr["error_no"]==0){
            //获取文章分类
            $paramsObj=paramsObj();
            $paramsObj->params=array(
                "index"=>$dataObj->request->index,
                "verify"=>0,
            );
            $checkResult=app("S_Index_adPosition")->infoByIndex($paramsObj);
            if($checkResult["error_no"]=="0"){
                $adPositionResult=$checkResult["result"];
                if($adPositionResult){
                    $paramsObj=paramsObj();
                    $paramsObj->params=array(
                        "positionId"=>$adPositionResult["id"],
                        "offset"=>$dataObj->request->offset,
                        "limit"=>$dataObj->request->limit,
                    );
                    $checkResult=app("S_Index_adManage")->getList($paramsObj);
                    if($checkResult["error_no"]=="0"){
                        $adManageResult=$checkResult["result"];
                        if($adManageResult){
                            $dataObj->result=$adManageResult;
                        }
                    }else{
                        $final_arr=logCallErrorMsg($final_arr,$checkResult);
                    }
                }
            }else{
                $final_arr=logCallErrorMsg($final_arr,$checkResult);
            }
        }
        if($final_arr["error_no"]==0){
            $final_arr["result"]=$dataObj->result;
        }
        return $final_arr;
    }

    public function __call($name,$arguments)
    {
        return recordLogMsgLevelTwo(app("errorLevel")::E_WARNING,app("errorCode")::UNDEFINED_METHOD,lang("sys.noMethodDefined"),$name,$arguments);
    }
}